[#ftl]
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>[#assign module]a/${_site_}/channels/${_channel_}/templatecfgs[/#assign][#assign moduleName="栏目"]
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="${base}/commonjs/jquery1.7.2/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="${base}/commonjs/jquery-forms.js"></script>
<script type="text/javascript" src="${base}/commonjs/jquery.select.js"></script>
<script type="text/javascript" src="${base}/commonjs/artDialog4/artDialog.source.js?skin=blue"></script>
<script type="text/javascript" src="${base}/commonjs/artDialog4/plugins/iframeTools.source.js"></script>
<title>频道的模板配置</title>
</head>
<body>
<script type="text/javascript">
$(function(){
    $("#select_template_channels").createSelect("${base}/a/${_site_}/channels/templatechannels", {}, function(row){
        return [row.id, row.cell[1]+"["+row.cell[0]+"]"];
    },  ${(_channel.parent.id)!0});
  $("#btadditem").bind("click", function(){
    $("#additemform").ajaxForm({
      dataType: "json",
      success: function(json){
        if(!json.success){
          art.dialog.through({
            title: "[#if (item.id)??]编辑${moduleName}信息[#else]添加新${moduleName}[/#if]失败",
            icon: "error",
            content: "[#if (item.id)??]编辑${moduleName}信息[#else]添加新${moduleName}[/#if]失败！<br>"+json.err,
            width: 250,
            height: 150,
            background: '#EEE', // 背景色
            opacity: 0.05,  // 透明度
            lock: true,
            ok: true
          });
        }else{
          try{
            window.location.reload();
          }catch(e){
             try{
                window.location.reload();
             }catch(e){
                 window.location.reload();
             }
          }
          art.dialog.close();
        }
      }
    });
  });
});
var o_settings = [[#list _dicts as _dict][${_dict.id}, ${(_dict.channelConfig.template.id)!0}, "${(_dict.path)!}"],[/#list]];
var n_settings = [];
function selectMonitor(select){
    select = $(select);
    var dictid = select.attr("id").substring(7);
    var value = select.val();
    var found = false;
    for(var i=0; i<n_settings.length; i++){
        if(n_settings[i][0]==dictid){
            n_settings[i][1] = value;
            found = true;
            break;
        }
    }
    if(!found){
        n_settings.push([dictid, value, $("#input_"+dictid).val()]);
    }
}
function inputMonitor(input){
    input = $(input);
    var dictid = input.attr("id").substring(6);
    var value = input.val();
    var found = false;
    for(var i=0; i<n_settings.length; i++){
        if(n_settings[i][0]==dictid){
            n_settings[i][2] = value;
            found = true;
            break;
        }
    }
    if(!found){
        n_settings.push([dictid, $("#select_"+dictid).val(), value]);
    }
}
function submitChanges(){
    var settings = [];
    for(var i=0; i<n_settings.length; i++){
        var dictid = n_settings[i][0];
        var selectvalue = n_settings[i][1];
        var inputvalue = n_settings[i][2];
        var equal = false;
        for(var j=0; j<o_settings.length; j++){
            if(o_settings[j][0] == dictid){
                equal = (o_settings[j][1]==selectvalue)&&(o_settings[j][2]==inputvalue);
                break;
            }
        }
        if(!equal){
            settings.push([dictid, selectvalue, inputvalue]);
        }
    }
    var dictid = [];
    var tmplid = [];
    var path = [];
    for(var i=0; i<settings.length; i++){
        dictid.push(settings[i][0]);
        tmplid.push(settings[i][1]);
        path.push(settings[i][2]);
    }
    $.post("${base}/${module}/edit.do", $.param({dictid: dictid, tmplid: tmplid, path: path}, true), function(text){
        if(!!text.success){
            alert("保存成功！");
            window.location.reload();
        }
    });
    
}
function customizeComplets(id){
  var url = '${base}/${module}/'+id+'/index.html';
  art.dialog.open(url, {
    title: '视角模板配置',
    background: '#EEE', // 背景色
    opacity: 0.05,  // 透明度
    width: 850,
    height: 550
  }).lock();
}

function showTemplates(){
  var url = '${base}/a/${_site_}/templates/index.html';
  art.dialog.open(url, {
    title: '模板管理',
    background: '#EEE', // 背景色
    opacity: 0.05,  // 透明度
    width: 850,
    height: 550
  }).lock();
}
$(function(){
    var templates = [];
[#list _dicts as _dict]
    [#if _dict_index==0]
        $("#select_${_dict.id}").createSelect("${base}/a/${_site_}/templates/list", {
            pageNo:1,pageSize:999
        }, function(row){
            var data = [row.id, row.id+":"+row.cell[1]];
            templates.push(data);
            return data;
        }, ${(_dict.channelConfig.template.id)!0}[#if _dict_index<_dicts?size-1], function(){
            fillOthers();
        }[/#if]);
    [#else]
        [#if _dict_index==1]
        function fillOthers(){
        [/#if]
             $("#select_${_dict.id}").createSelect(templates, ${(_dict.channelConfig.template.id)!0});
        [#if _dict_index==_dicts?size-1]
        }
        [/#if]
    [/#if]
[/#list]


});
</script>
<h1>${(_channel.name)!'未知栏目配置'} | [#switch _channel.type][#case 0]容器类型[#break][#case 1]标准列表栏目类型[#break][#case 2]单页栏目类型[#break][#case 3]半异构标准栏目类型[#break][#case 4]半异构单页栏目类型[#break][#case 5]纯异构栏目类型[#break][/#switch]</h1>
<table>
    <tr>
        <th>模板类别</th>
        <th>模板配置</th>
        <th>页面标题</th>
        <th>组件配置</th>
    </tr>
[#list _dicts as _dict]
    <tr>
        <td>${_dict.name}</td>
        <td><select id="select_${_dict.id}" onchange="selectMonitor(this);"><option value="0">--请选择模板--</option></select></td>
        <td><input type="text" id="input_${_dict.id}" onchange="inputMonitor(this);" value="${(_dict.channelConfig.path)!((_channel.name)!)}"></td>
        <td>[#if _dict.channelConfig??][#if _dict.id>2]无需配置[#else]<input type="button" value="配置组件" onclick="customizeComplets(${(_dict.channelConfig.id)!0})">[/#if][#else]&nbsp;[/#if]</td>
    </tr>
[/#list]
</table>
<br>
<input type="button" value="提交变更" onclick="submitChanges();">
<input type="button" value="模板管理" onclick="showTemplates();">
<form id="additemform" action="${base}/a/{site}/channels/copytemplet" method="POST">
<input type="hidden" name="id" value=${(_channel.id)!0}>
<select id="select_template_channels" name="tempchid">
<option value="0">--请选择模板栏目--</option>
<br>
<input type="submit" value="保存" id="btadditem">
</select>
</form>
</body>
</html>